import {baseurl} from "../../apis/index";
import api from "../../apis/action";

Component({
  properties: {
    layout: {
      type: Array,
      value: [
        {
          icon: "/assets/home-icons/calendar.svg",
          src: [`${baseurl}/static/calendar1.jpg`, `${baseurl}/static/calendar2.jpg`],
          title: "校历"
        },
        {
          icon: "/assets/home-icons/map.svg",
          src: [],
          title: "地图"
        },
        {
          icon: "/assets/home-icons/address_book.svg",
          src: [],
          title: "电话本"
        },
        {
          icon: "/assets/home-icons/schedule.svg",
          src: [],
          title: "时间表"
        }
      ]
    }
  },
  lifetimes: {
    async attached() {
      const layout = await api.getActionLayout();
      this.setData({
        layout: layout
      });
    }
  },
  data: {},
  methods: {
    openImage: function (e) {
      const src = e.currentTarget.dataset["src"];
      if (src.length !== 0) {
        wx.previewImage({
          urls: src,
          fail(res) {
            wx.showToast({
              icon: "error",
              duration: 2000,
              title: "图片打开失败"
            })
          }
        })
      }
    }
  }
});
